// FruitGenerator.java
package game;

import java.util.ArrayList;
import java.util.List;
import utils.RandomUtils;

public class FruitGenerator {
    private static final String[] FRUITS = {"🍎", "🍌", "🍒", "🍓", "🍇", "🍍", "🥝", "🍊"};
    private static final String BOMB_SYMBOL = "💣"; // 炸弹符号
    private static final String[] SPECIAL_FRUITS = {"🍉"}; //特殊水果
    private static final int MIN_FRUITS = 1;
    private static final int MAX_FRUITS = 3;
    private static final int WIDTH = 800;
    private static final int HEIGHT = 600;
    private int bombChance;
    private int specialFruitChance;

    public FruitGenerator(int bombChance, int specialFruitChance) {
        this.bombChance = bombChance;
        this.specialFruitChance = specialFruitChance;
    }

    public List<Fruit> generateFruits() {
        List<Fruit> fruits = new ArrayList<>();
        int numFruits = RandomUtils.getRandomInt(MIN_FRUITS, MAX_FRUITS);
        for (int i = 0; i < numFruits; i++) {
            if (RandomUtils.getRandomInt(1, 100) <= bombChance) {
                // 生成炸弹
                int x = RandomUtils.getRandomInt(0, WIDTH - 100);
                int y = HEIGHT;
                double vx = RandomUtils.getRandomDouble(-3, 3);
                double vy = RandomUtils.getRandomDouble(-10, -7);
                fruits.add(new Fruit(BOMB_SYMBOL, x, y, vx, vy, true, false, 0));
            } else if (RandomUtils.getRandomInt(1, 100) <= specialFruitChance) {
                // 生成特殊水果
                String fruitSymbol = RandomUtils.getRandomElement(List.of(SPECIAL_FRUITS));
                int x = RandomUtils.getRandomInt(0, WIDTH - 100);
                int y = HEIGHT;
                double vx = RandomUtils.getRandomDouble(-3, 3);
                double vy = RandomUtils.getRandomDouble(-9, -7);
                int specialEffect = RandomUtils.getRandomInt(1, 3); // 新增特殊效果，范围改为 1 - 3
                fruits.add(new Fruit(fruitSymbol, x, y, vx, vy, false, true, specialEffect));
            } else {
                // 生成普通水果
                String fruitSymbol = RandomUtils.getRandomElement(List.of(FRUITS));
                int x = RandomUtils.getRandomInt(0, WIDTH - 100);
                int y = HEIGHT;
                double vx = RandomUtils.getRandomDouble(-3, 3);
                double vy = RandomUtils.getRandomDouble(-9, -7);
                fruits.add(new Fruit(fruitSymbol, x, y, vx, vy, false, false, 0));
            }
        }
        return fruits;
    }
}